
from Common import sql_content

class _Login(object):

    def __init__(self):
        self.sql_content = sql_content.sql_content()
        self.loginName = ''
        self.password = ''
        self.__Login_List = []

    def _login(self,username_form,password_form):
        print('login——.py', username_form, password_form)
        self.loginName = username_form
        self.password = password_form
        __selectByName = self.selectByName()
        if len(__selectByName)==0:
            return 0
        elif __selectByName[0].get('Password') == password_form:
            #print('jjjjj',__selectByName[0].get('Password'))
            return 1

    def selectByName(self):
        Login_Dict = {}

        con = self.sql_content.conten()
        sql_login = "select * from logins WHERE LoginName='%s'"%(self.loginName)
        cursor = con.cursor()
        cursor.execute(sql_login)
        rs = cursor.fetchall()
        for row in rs:
            Login_Dict['LoginId']=row[0]
            Login_Dict['Username']=row[1]
            Login_Dict['Password']=row[2]
            Login_Dict['Email']=row[3]
            Login_Dict['LoginTime']=row[4]
            Login_Dict['RegisterDateTime']=row[5]
            Login_Dict['RegisterIp']=row[6]
            Login_Dict['LastLoginDateTime']=row[7]
            Login_Dict['LastLoginIp']=row[8]
            Login_Dict['Remark']=row[9]
            self.__Login_List.append(Login_Dict)
        #print('wocao', LoginId, Username)
        print('login_selectByName',self.__Login_List)

        cursor.close()
        con.close()

        return self.__Login_List



